#ifndef SCHEDULER_H_
#define SCHEDULER_H_

/*INCLUDES *******************************************************************/
#include "ses_common.h"

/* DEFINES & MACROS **********************************************************/

#define SCHEDULER_ENTRIES		10
#define SEC_MS       			(uint16_t)1000
#define HOUR_MIN      			(uint8_t)60
#define HOUR_MS    				(uint32_t)3600000
#define MIN_MS    				(uint16_t)60000

/*GLOABLE VARIABLE***********************************************************/
struct type_timeRTC {		//New structure for saving Time in a single bundle
	uint8_t hour;
	uint8_t minute;
	uint8_t second;
	uint16_t milli;
};

/* TYPES ********************************************************************/

/**type of function pointer for tasks
 */
typedef void (*task_t)(void);

/* FUNCTION PROTOTYPES *******************************************************/

void sysms_increment();

void scheduler_update();
/**
 * Initializes the task scheduler.
 */
void scheduler_init();

/**
 * Runs scheduler in an infinite loop.
 */
void scheduler_run();

/**
 * Adds a new task to the scheduler. A scheduled task is executed once after the given
 * time period, if period==0. A periodic tasks execution is repeated depending on its period.
 *
 * @param task      valid pointer to task
 * @param expire    time counter
 * @param period    time period
 * @return          FALSE = no error, TRUE = scheduler full/error
 */bool scheduler_add(task_t task, uint16_t expire, uint16_t period);

/**
 * Removes a timer task from the scheduler.
 *
 * @param task	pointer to task
 * */
void scheduler_remove(task_t task);

/**
 * a Function for returning time in milliseconds
 * by reading the time from @systime_ms
 */
uint32_t scheduler_getTime();

/**
 * sets system time in milliseconds
 */
void scheduler_setTime(uint32_t);

/**
 * get system time in Real Time Clock format
 * using @ms_convertTime
 * to convert from 32 bits integer to RTC type
 *
 */
void scheduler_getTimeRTC(struct type_timeRTC *time);

/**
 * Sets system time from Real Time Clock
 * into an uint32_t variable
 * Then use @scheduler_setTime to set @systime_ms
 */
void scheduler_setTimeRTC(const struct type_timeRTC *time);

/**
 * @ms_convertTime role to convert system Time from integer format
 * into a RTC type constructed of
 */
void ms_convertTime(uint32_t mstime, struct type_timeRTC *time);

#endif /* SCHEDULER_H_ */
